package geograph.china;

import java.util.ArrayList;
import java.util.List;

/**
 * Title:
 * Created by Myth on 2017/8/17.
 */
public class City {
    private String cityName;
    private String cityEnglishName;
    private List<District> districtList;

    public City(String cityName, String cityEnglishName) {
        this.cityName = cityName;
        this.cityEnglishName = cityEnglishName;
        districtList = new ArrayList<>();
    }

    public String getCityEnglishName() {
        return cityEnglishName;
    }

    public List<District> getDistrictList() {
        return districtList;
    }

    public District district(String englishName) {
        for (District district : districtList) {
            if (district.getDistrictEnglishName().equals(englishName))
                return district;
        }
        return null;
    }
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        City city = (City) o;

        if (cityName != null ? !cityName.equals(city.cityName) : city.cityName != null) return false;
        return cityEnglishName != null ? cityEnglishName.equals(city.cityEnglishName) : city.cityEnglishName == null;
    }

    @Override
    public int hashCode() {
        int result = cityName != null ? cityName.hashCode() : 0;
        result = 31 * result + (cityEnglishName != null ? cityEnglishName.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "{\"name\":\"" + cityName +"\", \"english_name\":\"" + cityEnglishName + "\"}";
    }
}
